package com.lian.hope.config;

import com.lian.hope.interceptors.LoginInterceptor;
import com.lian.hope.interceptors.PermissionInterceptor;
import com.lian.hope.properties.WeChatProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
@Slf4j
public class WebConfig implements WebMvcConfigurer {
    private final LoginInterceptor loginInterceptor;
private final PermissionInterceptor permissionInterceptor;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 添加映射路径，允许所有路径跨域
        registry.addMapping("/**")
            // 允许所有来源跨域
            .allowedOriginPatterns("*")
            // 允许所有请求方法跨域
            .allowedMethods("*")
            // 允许所有请求头跨域
            .allowedHeaders("*")
            // 是否允许携带凭证（cookies）
            .allowCredentials(true);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/users/**","/notifications/**").excludePathPatterns(
            "/login","/users/operateList","/users/send-sms");




   registry.addInterceptor(permissionInterceptor);

    }
}
